<?php

use yii\db\Migration;

class m180902_113703_create_agent_log extends Migration
{
    public function safeUp()
    {
        $this->createTable('{{%agent_log}}', [
            'id' => $this->primaryKey(),
            'agent_id' => $this->integer()->notNull()->comment('代理商编号'),
            'type' => $this->string(32)->notNull()->comment('类型'),
            'time' => $this->integer()->notNull()->comment('时间'),
            'info' => $this->string(128)->notNull()->comment('信息'),
            'data' => $this->text()->comment('数据'),
        ]);
        $this->createIndex('fk_agent_log_agent1_idx', '{{%agent_log}}', ['agent_id']);
        try {
            $this->addForeignKey('fk_agent_log_agent1', '{{%agent_log}}', ['agent_id'], '{{%agent}}', ['id']);
        } catch (Exception $e) {
            Yii::error($e->getMessage());
        }
    }

    public function safeDown()
    {
        $this->dropTable('{{%agent_log}}');
    }
}
